package com.linzhaowei.headhuntingservice.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;


import com.linzhaowei.headhuntingservice.JobInformationDetail;
import com.linzhaowei.headhuntingservice.bean.JobInformation;
import com.linzhaowei.headhuntingservice.R;

import java.util.List;

public class JobInformationAdapter extends RecyclerView.Adapter<JobInformationAdapter.ViewHolder> {
    private List<JobInformation> jobInformationList;


    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView job_text;
        TextView job_interviewer;
        TextView job_salary;
        TextView job_address;

        View job_view;


        ViewHolder(View view){
            super(view);
            job_view=view;
            job_text=view.findViewById(R.id.job_text);
            job_interviewer=view.findViewById(R.id.job_interviewer);
            job_salary=view.findViewById(R.id.job_salary);
            job_address=view.findViewById(R.id.job_address);
        }
    }

    public JobInformationAdapter(List<JobInformation> list){

        jobInformationList=list;
    }

    @Override
    public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType){
        View view=LayoutInflater.from(parent.getContext())
                .inflate(R.layout.job_information_item,parent,false);
        final ViewHolder holder=new ViewHolder(view);

        holder.job_view.setOnClickListener(v -> {
            int position=holder.getAdapterPosition();
            JobInformation jobInformation=jobInformationList.get(position);
            Intent intent=new Intent(view.getContext(), JobInformationDetail.class);
            intent.putExtra("job_information_id",jobInformation.getId());
            view.getContext().startActivity(intent);
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder,int position){
        JobInformation jobInformation=jobInformationList.get(position);
        String salary=jobInformation.getSalary()+"/月";
        holder.job_text.setText(jobInformation.getName());
        holder.job_salary.setText(salary);
        holder.job_interviewer.setText(jobInformation.getInterviewer_name());
        holder.job_address.setText(jobInformation.getAddress());
    }

    @Override
    public int getItemCount(){
        return jobInformationList.size();
    }





}
